package com.example.video.common.exception;

import com.example.video.common.util.ResponseWrap;
import com.example.video.common.util.ResponseWrapUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 全局异常处理
 * <p/>
 *
 * @author : yj
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    //添加全局异常处理流程
    @ExceptionHandler(value= RuntimeException.class)
    public Object MethodArgumentNotValidHandler(HttpServletRequest request,
                                                RuntimeException exception) {
        exception.printStackTrace();
        ResponseWrap<Object> error = ResponseWrapUtil.error(exception.getMessage());
        return error;
    }
}
